package com.xlh.service.problem.impl;

import com.xlh.dao.problem.ForbiddenMapper;
import com.xlh.dao.problem.ForbiddenMapperExt;
import com.xlh.dto.problem.ForbiddenDTO;
import com.xlh.param.problem.ProblemParam;
import com.xlh.pojo.problem.Forbidden;
import com.xlh.pojo.problem.ForbiddenExample;
import com.xlh.service.problem.ForbiddenService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ForbiddenServiceImpl implements ForbiddenService {

    @Autowired
    private ForbiddenMapper mapper;
    @Autowired
    private ForbiddenMapperExt mapperExt;

    @Override
    public Forbidden selectByUserIdCourseId(Long userId, Long courseId) {
        ForbiddenExample example = new ForbiddenExample();
        example.createCriteria().andUserIdEqualTo(userId).andCourseIdEqualTo(courseId);
        List<Forbidden> resultList = mapper.selectByExample(example);
        return CollectionUtils.isEmpty(resultList) ? new Forbidden(): resultList.get(0);
    }

    @Override
    public List<ForbiddenDTO> forbiddenWordsListPage(ProblemParam problemParam) {
        return mapperExt.forbiddenWordsListPage(problemParam);
    }

    @Override
    public void insertSelective(Forbidden forbidden) {
        mapper.insertSelective(forbidden);
    }

    @Override
    public void updateByPrimaryKeySelective(Forbidden forbidden) {
        mapper.updateByPrimaryKeySelective(forbidden);
    }
}
